package com.lzy.mall.order.aop;

import com.lzy.mall.order.annotation.LzyLog;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author lzy
 * @date 2021/9/30 15:39
 */
@Component
@Aspect
@Slf4j
public class LzyLogAspect {
    @Pointcut("@annotation(com.lzy.mall.order.annotation.LzyLog)")
    private void pointcut(){}

    @Before("pointcut() && @annotation(logger)")
    public void advice(JoinPoint joinPoint, LzyLog logger) {
        log.info("[方法名：{}][类路径：{}]-日志内容-[{}]",
                joinPoint.getSignature().getName(),
                joinPoint.getSignature().getDeclaringTypeName(),
                logger.value());
        Object[] args = joinPoint.getArgs();
        for (Object arg : args) {
            System.out.println(arg);
        }
    }
}
